//package com.qujia.station.service.impl;
//
//import cn.hutool.core.date.DateUtil;
//import com.qujia.common.exception.CustomException;
//import com.qujia.common.utils.StringUtils;
//import com.qujia.station.domain.Station;
//import com.qujia.station.domain.SysAppUserInfo;
//import com.qujia.station.domain.dto.SyncUserDto;
//import com.qujia.station.mapper.AppUserInfoMapper.java;
//import com.qujia.station.service.IAppUserInfoService;
//import com.qujia.station.service.IStationService;
//import com.qujia.station.service.UserSyncService;
//import com.qujia.system.mapper.AppUserInfoUserMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections.CollectionUtils;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.util.Date;
//import java.util.List;
//import java.util.Objects;
//import java.util.concurrent.CountDownLatch;
//
//@Service
//@Slf4j
//public class UserSyncServiceImpl implements UserSyncService {
//    @Resource
//    private IStationService stationService;
//
//    @Resource
//    private IAppUserInfoService appUserInfoUserService;
//
//    @Resource
//    private AppUserInfoMapper.java appUserInfoMapper;
//
//
//    @Override
//    public Boolean insertUser(SyncUserDto syncUserDto) {
//        Boolean res = checkUser(syncUserDto);
//        if(!res){
//            throw new CustomException("用户已存在");
//        }
//
////        Station station = stationService.selectStationById(Long.valueOf(syncUserDto.getStationId()));
////        if(Objects.isNull(station.getStationId())){
////            throw new CustomException("没有对应的油企");
////        }
//
//        SysAppUserInfo sysAppUserInfo = new SysAppUserInfo();
//
//
//        sysAppUserInfo.setMobilePhone(syncUserDto.getMobilePhone());
//        sysAppUserInfo.setUserSource("yunhua");
//        sysAppUserInfo.setStationId(Long.valueOf(syncUserDto.getEnterpriseId()));
//        sysAppUserInfo.setRegisteDate(new Date());
//        sysAppUserInfo.setYunhuaUserId(syncUserDto.getYunhuaUserId());
//        int i = appUserInfoUserService.insertAppUserInfo(sysAppUserInfo);
//        return true;
//    }
//
//    @Override
//    @Async("threadPoolTaskExecutor")
//    public Boolean batchInsertUser(List<SyncUserDto> syncUserDto,CountDownLatch countDownLatch) {
//        log.info("开始批量同步用户信息【{}】",syncUserDto);
//        try {
//            for (SyncUserDto userDto : syncUserDto) {
//                if(StringUtils.isEmpty(userDto.getYunhuaUserId()) || StringUtils.isEmpty(userDto.getEnterpriseId())){
//                    continue;
//                }
//                userDto.setUserSource("yunhua");
//                userDto.setRegisteDate(new Date());
//                appUserInfoMapper.insertOrUpdateYunHuaUserId(userDto);
//            }
////            appUserInfoMapper.batchInsertYunHuaUser(syncUserDto);
//        }finally {
//            countDownLatch.countDown();
//        }
//        log.info("开始批量同步用户结束===============");
//        return true;
//    }
//
//    private Boolean checkUser(SyncUserDto syncUserDto) {
//
//        SysAppUserInfo sysAppUserInfoSelect = new SysAppUserInfo();
//        sysAppUserInfoSelect.setYunhuaUserId(syncUserDto.getYunhuaUserId());
//
//        List<SysAppUserInfo> userList = appUserInfoMapper.selectList(sysAppUserInfoSelect);
//
//        if(CollectionUtils.isNotEmpty(userList)){
//            return false;
//        }
//        return true;
//    }
//
//
//}
